#include "stdafx.h"
#include "SoundSystem.h"

using namespace MomogenkyouSystem;

IXAudio2				*	SoundSystem::DeviceManager(NULL);
IXAudio2MasteringVoice	*	SoundSystem::MasteringVoice(NULL);

bool	SoundSystem::Initialize(const HWND		& param_WindowHandle, 
								const HINSTANCE & param_WindowInstance)
{
	UNREFERENCED_PARAMETER(param_WindowHandle);
	UNREFERENCED_PARAMETER(param_WindowInstance);

	HRESULT	_Result	= S_OK;
	size_t	_DeviceFlag = 0;

#if _DEBUG
	_DeviceFlag |= XAUDIO2_DEBUG_ENGINE;
#endif

	_Result	=	XAudio2Create(&DeviceManager, _DeviceFlag, XAUDIO2_DEFAULT_PROCESSOR);
	ASSERT(_Result == S_OK, "Error creating XAudio2 Device");


	_Result =	DeviceManager->CreateMasteringVoice(&MasteringVoice);
	ASSERT(_Result == S_OK, "Error creating XAudio2 Mastering Voice");
	
	_Result = DeviceManager->StartEngine();
	ASSERT(_Result == S_OK, "Error starting XAudio2 Processing thread");
	WriteCommandLine("SoundSystem > Initialized");
	return	true;
}

void	SoundSystem::Shutdown()
{
	DeviceManager->StopEngine();
	MasteringVoice->DestroyVoice();

	DeviceManager->Release();

	WriteCommandLine("SoundSystem > Shutdown");
}

void	SoundSystem::Update(const float &fInterval)
{
	UNREFERENCED_PARAMETER(fInterval);
}